﻿<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://www.ufida.com/lfw" prefix="lfw" %>
<%@ taglib uri="http://www.ufida.com/uif" prefix="uif" %> 
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<html>
	<head>
		<lfw:base/>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<uif:import/>
		<script type='text/javascript' src='code/webbxmainquery'></script>
		<script type='text/javascript' src='/lfw/frame/script/chart/ChartComp.js'></script>
		<style>
			* {
				font: 12px;
				FONT-FAMILY: arial;
			}
		</style>
	</head>
	<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" scroll=no onload="pageBodyScript()" style="background-color:transparent">
		<lfw:pageModel className="nc.lfw.finance.main.WebBxMainPageSPPageModel">
			<lfw:layout type="border" border="0">

				<lfw:layoutPanel align="center" position="center">
					<lfw:layout type="flowh">
						<lfw:layoutPanel width="120" align="center">
					    		<lfw:radio id="sprcy" ></lfw:radio>
					    	</lfw:layoutPanel>
						<lfw:layoutPanel width="120" align="center">
					    		<lfw:radio id="sprcn" ></lfw:radio>
					    	</lfw:layoutPanel>
					</lfw:layout>
				</lfw:layoutPanel>

				<lfw:layoutPanel align="center" position="bottom" height="34">
					<lfw:button id="quickQueryBtn"></lfw:button>
				</lfw:layoutPanel>

			</lfw:layout>
		</lfw:pageModel>
	</body>
</html>	
<script language="javascript">
	function externalInit()
	{   
	}

	function uniteDate(value)
	{
		var month = value.getMonth() + 1;
		var today = value.getDate();
		if(month < 10) month = '0' + month;
		if(today < 10) today = '0' + today;
		var year = value.getYear();
		//firefox sub 1900
		if(year < 1900)
			year += 1900;
		return year + "-" + month + "-" + today;
	}
	
	
	function doCommonQuery(value){
		var sql = '';
		var lDate = getLoginDate();
		var today = new Date(lDate.replace(/\-/g,"/"));
		var dt = new Date(lDate.replace(/\-/g,"/"));
		var monthArr = new Array("31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31");
		if(isRunNian(dt.getFullYear()))
			monthArr[1] = "29";
		if(value == 'week'){//从今天向前推7天
			var weekstart;
			var mv = dt.getDate();//月中哪天
			if(mv <= 7){
				dt.setMonth(dt.getMonth()-1);
				weekstart = parseInt(monthArr[dt.getMonth()]) + (parseInt(mv) - 7);
				dt.setDate(weekstart);
			}
			else{
				weekstart = mv - 7;
				dt.setDate(weekstart);
			}
			sql = "'"+ this.uniteDate(dt) + "' <= djrq and djrq <= '" + this.uniteDate(today) + "'";
		}
		else{
			var k;
			if(value == 'month') k=1;
			else if(value == 'twomonth') k=2;
			else if(value == 'threemonth') k=3;

	//		if(dt.getMonth() == 0)//如果是元月则从全部从元月一号开始
	//			dt.setDate(1);
	//		else{
				dt.setMonth(dt.getMonth() - k);
				if(parseInt(monthArr[dt.getMonth()-k]) < dt.getDate())//如果上几月的天数小于本月,那就从那月的上月1号开始
					dt.setDate(1);
	//		}
			sql = "'"+ this.uniteDate(dt) + "' <= djrq and djrq <= '" + this.uniteDate(today) + "'"
		}
		return sql;
	}
	
	function doQuickQuery()
	{  
		//var sql = ''
		//if(parent.datesql == null){
		//	sql = doCommonQuery('threemonth');
		//}else{
		//	sql = doCommonQuery(parent.datesql);
		//}
		
		$query();
	}
	
	function $query()
	{
		parent.showProgressDialog(trans('ml_wait'));
		var dsId = '<%=request.getParameter("dsId")%>';
		var targetDs = parent.getDataset(dsId);
		//var queryParamArray = '';
		//log("quick query condition sql: " + sql);
		var spparam = '';
		var approveAdvice = getComponent("sprcy").getChecked();
		var approveAdviceText = '';
		if(approveAdvice){
			approveAdviceText = 'approve';
		}else{
			approveAdviceText = 'backward';
		}
		var Rows = targetDs.getSelectedRows();
		//var indexs = new Array();
		for(var i = 0; i < Rows.length;i++){			
			spparam +=Rows[i].getCellValue(targetDs.nameToIndex('pk_jkbx'))+','+Rows[i].getCellValue(targetDs.nameToIndex('djlxbm'))+'$';
			//alert(targetDs.getRowIndex(Rows[i]));
			//indexs.push(targetDs.getRowIndex(Rows[i]));
		}
		var cmd = new CommonCommand("approves");
		var returnArgs = [targetDs,parent];
    		cmd.setParameter("spcs=" + spparam + "&approveAdvice=" + approveAdviceText);
    		cmd.setReturnArgs(returnArgs);
    		cmd.setReturnFunc(JkbxplApproveReturnFun);
   		cmd.setCallObj(this);
   		cmd.exec();
		//targetDs.deleteRows(indexs);
		

		//targetDs.addReqParameter('spcs', spparam);
		//targetDs.addReqParameter('WEBBX_MAIN_QUERY', sql);
		//targetDs.addReqParameter('WEBBX_MAIN_ADVANCED_QUERY_FLAG','N');
		//targetDs.addReqParameter(IDatasetConstant.FROM_QUERY_TEMPLATE, "false");
		//var args = [targetDs];
		
		//var loader = new DatasetLoader(targetDs);
		//loader.setKeyValue(Dataset.MASTER_KEY);
		//loader.setReturnFunc($qryReturnFunc);
		//loader.setReturnArgs(args);
		//loader.load(parent);
		//parent.hideDialog("sp_dialog","true");
	}
	/**
 	* 单据审批的回调函数
 	*/
	function JkbxplApproveReturnFun(xml,returnArgs, isSuccess)
	{	
		parent.hideProgressDialog();
		parent.hideDialog("sp_dialog","true");
		if(isSuccess){
			alert(trans('ml_operationsuccess'));
			var targetDs = returnArgs[0];
			var sql = ''
			if(parent.datesql == null){
				sql = doCommonQuery('threemonth');
			}else{
				sql = doCommonQuery(parent.datesql);
			}
			targetDs.addReqParameter('WEBBX_MAIN_ADVANCED_QUERY_FLAG','N');
			targetDs.addReqParameter(IDatasetConstant.FROM_QUERY_TEMPLATE, "false");
			targetDs.addReqParameter("IF_HAVE_OVER" ,"N");
			//var args = [targetDs];
		
			var loader = new DatasetLoader(targetDs);
			loader.setKeyValue(Dataset.MASTER_KEY);
			//loader.setReturnFunc($qryReturnFunc);
			//loader.setReturnArgs(args);
			loader.load(returnArgs[1]);
		}
	
	};
	
//	function getQuickQuerySql()
//	{	
//		if(parent.datesql == null){
//			alert('ok');
//		}
//		alert(parent.datesql);	
//		sql = '1=1';
//		return sql;
//	}
	
	function $qryReturnFunc(args, isSuccess) {
		if(isSuccess){
			var ds = args[0];
			if(ds.getRowCount() > 0 && ds.getSelectedIndex() == -1)
				ds.setRowSelected(0);
		}
		parent.hideDialog("quickquery_dialog", true);
	}
	
	function getMainFrame() {
		return parent.mainFrame;
	}
</script>
